package com.wlps.controller;

import com.wlps.entity.Client;
import com.wlps.entity.Order;
import com.wlps.result.ResultPageVo;
import com.wlps.result.ResultVo;
import com.wlps.service.IMissionListService;
import com.wlps.service.IPurchaseReceiptService;
import com.wlps.service.IReturnOutOfStockService;
import com.wlps.service.function.AbstractController;
import com.wlps.vo.warehousecenter.pickup.MissionListVo;
import com.wlps.vo.warehousecenter.pickup.PickupVo;
import com.wlps.vo.warehousecenter.warehoused.ReturnOutOfStockUpdateVo;
import com.wlps.vo.warehousecenter.warehoused.ReturnOutOfStockVo;
import com.wlps.vo.warehousecenter.warehoused.WarehousedVo;
import com.wlps.vo.warehousecenter.warehousing.PurchaseReceiptUpdateVo;
import com.wlps.vo.warehousecenter.warehousing.PurchaseReceiptVo;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 库房管理
 * </p>
 *
 * @author ZWYZY
 * @since 2020/7/31
 */
@RestController
@RequestMapping("/api/warehouse")
@Slf4j
@Validated
@Api(tags = "库房管理", description = "")
public class WarehouseCenter extends AbstractController {
    @Override
    public boolean judgeHasCommodity(long id) {
        return false;
    }

    @Override
    public Order generateOrder(Client client, long id) {
        return null;
    }

    public void dealWithOrder(Order order) {

    }

    @Autowired
    IPurchaseReceiptService purchaseReceiptService;

    @Autowired
    IReturnOutOfStockService returnOutOfStockService;

    @Autowired
    IMissionListService missionListService;

    @GetMapping("/getPurchaseReceiptVo")
    @ApiOperation(value = "分页显示入库单")
    public ResultPageVo<List<PurchaseReceiptVo>> getPurchaseReceiptVo(
            @ApiParam(value = "页数号（默认1）")
            @RequestParam(required = false, defaultValue = "1") int pageNum,
            @ApiParam(value = "页条数（默认10）")
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "排序（默认为true）")
            @RequestParam(required = false, defaultValue = "true") boolean sort,
            @ApiParam(value = "购货入库单号")
            @RequestParam(required = false) Long id
    ) {
        return purchaseReceiptService.getPurchaseReceiptVo(pageNum, pageSize, id);
    }

    @PostMapping("/editWarehouseingVo")
    @ApiOperation(value = "确认入库")
    public ResultVo editWarehouseingVo(@ApiParam(value = "购货入库单号", required = true) @NotNull(message = "入库单号不能为空") @RequestParam(required = false) Long id, @Validated @RequestBody PurchaseReceiptUpdateVo purchaseReceiptUpdateVo) {
        return purchaseReceiptService.editWarehouseingVo(id, purchaseReceiptUpdateVo);
    }

    @GetMapping("/getMissionList")
    @ApiOperation(value = "分页显示任务单")
    public ResultPageVo<List<MissionListVo>> getMissionList(
            @ApiParam(value = "页数号（默认1）")
            @RequestParam(required = false, defaultValue = "1") int pageNum,
            @ApiParam(value = "页条数（默认10）")
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "排序（默认为true）")
            @RequestParam(required = false, defaultValue = "true") boolean sort,
            @ApiParam(value = "任务单号")
            @RequestParam(required = false) Long id
    ) {

        return missionListService.getMissionList(pageNum, pageSize, id);
    }

    @PostMapping("/editPickupVo")
    @ApiOperation(value = "领货登记")
    public ResultVo editPickupVo(@Validated @RequestBody PickupVo pickupVo) {

        return missionListService.editPickupVo(pickupVo);
    }

    @GetMapping("/getWarehousedVo")
    @ApiOperation(value = "分页显示退货任务单")
    public ResultPageVo<List<WarehousedVo>> getWarehousedVo(
            @ApiParam(value = "页数号（默认1）")
            @RequestParam(required = false, defaultValue = "1") int pageNum,
            @ApiParam(value = "页条数（默认10）")
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "排序（默认为true）")
            @RequestParam(required = false, defaultValue = "true") boolean sort,
            @ApiParam(value = "退货任务单号")
            @RequestParam(required = false) Long id

    ) {

        return missionListService.getWarehousedVo(pageNum, pageSize, id);
    }

    @GetMapping("/editWarehousedVo")
    @ApiOperation("确认退货")
    public ResultVo editWarehousedVo(@NotNull(message = "退货任务单号不能为空") @ApiParam(value = "退货任务单id", required = true) @RequestParam(required = false) Long id) {
        return missionListService.editWarehousedVo(id);
    }


    @GetMapping("/getReturnOutOfStockVo")
    @ApiOperation(value = "分页显示出库单")
    public ResultPageVo<List<ReturnOutOfStockVo>> getReturnOutOfStockVo(
            @ApiParam(value = "页数号（默认1）")
            @RequestParam(required = false, defaultValue = "1") int pageNum,
            @ApiParam(value = "页条数（默认10）")
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "排序（默认为true）")
            @RequestParam(required = false, defaultValue = "true") boolean sort,
            @ApiParam(value = "出库单号")
            @RequestParam(required = false) Long id
    ) {
        return returnOutOfStockService.getReturnOutOfStockVo(pageNum, pageSize, id);
    }

    @PostMapping("/editReturnOutOfStockVo")
    @ApiOperation(value = "确认出库")
    public ResultVo editReturnOutOfStockVo(@NotNull(message = "出库单号不能为空") @ApiParam(value = "退货出库单号", required = true) @RequestParam(required = false) Long id, @Validated @RequestBody ReturnOutOfStockUpdateVo returnOutOfStockUpdateVo) {
        return returnOutOfStockService.editReturnOutOfStockVo(id, returnOutOfStockUpdateVo);
    }
}
